package com.zhuiyun.pm.sys.menu.controller;

import com.zhuiyun.pm.config.CommonResult;
import com.zhuiyun.pm.sys.menu.entity.MenuEntity;
import com.zhuiyun.pm.sys.menu.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 菜单管理
 * @Author lx
 * @Date 2023/3/13 9:58
 */
@RestController
@RequestMapping("/menu")
@CrossOrigin
public class MenuController {
    @Autowired
    MenuService menuService;

    /**
    * @Author lx
    * @Description 显示菜单信息
    * @Date 2023/3/20 11:01
    * @Return com.zhuiyun.pm.config.CommonResult
    */
    @GetMapping("/getByMenu")
    public CommonResult getByMenu(){
        return CommonResult.ok(menuService.getByMenu());
    }

    /**
    * @Author lx
    * @Description 模糊查询
    * @Date 2023/3/20 13:04
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param menuName
    */
    @GetMapping("/getAllMenuByName")
    public CommonResult getAllMenuByName(String menuName) {
        return  CommonResult.ok(menuService.getAllMenuByName(menuName));
    }

    /**
    * @Author lx
    * @Description 菜单新增
    * @Date 2023/3/13 15:36
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param menuEntity
    */
    @PostMapping("/saveMenu")
    public CommonResult saveMenu(MenuEntity menuEntity){
        return CommonResult.ok( menuService.saveMenu(menuEntity));
    }

    /**
    * @Author lx
    * @Description 删除菜单信息
    * @Date 2023/3/13 15:36
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param id
    */
    @DeleteMapping("/deleteMenuById")
    public CommonResult deleteMenuById(Integer id){
        return CommonResult.ok(menuService.deleteMenuById(id));
    }

    /**
    * @Author lx
    * @Description 修改菜单信息
    * @Date 2023/3/13 15:36
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param menuEntity
    */
    @PutMapping("/updateMenuById")
    public CommonResult updateMenuById(MenuEntity menuEntity){
        return CommonResult.ok(menuService.updateMenuById(menuEntity));
    }

    /**
    * @Author lx
    * @Description 实现动态路由
    * @Date 2023/3/13 15:39
    * @Return com.zhuiyun.pm.config.CommonResult
    */
    @GetMapping("/getMenuListByPower")
    public CommonResult getMenuListByPower(Integer id) {
        return  CommonResult.ok(menuService.getMenuListByPower(id));
    }


}
